function Ankhy_Mage_3()

------------------
	-- Cast Power Word: Fortitude
	if (vLastHoG == nil or (GetTime() - vLastHoG > 10)) then
	ccrCastBuffIfMissing("Frost Armor")
	vLastHoG = GetTime()
	return
	end
	 ---------------------
	 -- Cast Inner Fire
	ccrCastBuffIfMissing("Arcane Brilliance")
	 ---------------------
	-- Autoaccept LFR invite
	AcceptProposal();
	--------------------------
	if ccrPlayerIsCastingOrChanneling() then return end
	
		if not PlayerHasPet()
			then
			ccrCast("Summon Water Elemental")
			return
		end
	
		-- Invoker's Energy
		
		if not ccrPlayerHasBuff("Alter Time") then	
			if not ccrPlayerHasBuff("Invoker's Energy") and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
			if ccrPlayerMana() < 20 and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
			if not onCD("Alter Time") and ccrPlayerHasBuff("Invoker's Energy") and ccrUnitBuffDuration("player", "Invoker's Energy") <= 6 and not ccrPlayerIsCastingOrChanneling()
				and not ccrPlayerIsMoving()
				and (vLastHoG == nil or (GetTime() - vLastHoG > 3))
					then
					ccrCast("Evocation")
					vLastHoG = GetTime()
					return
			end
		end	
		
		-- Is in combat
		
		if ccrPlayerIsInCombat() then
		
			-- Survival
			
			if ccrPlayerHealth() <= 20
				and SpellIsReady("Ice Block")
					then
					SpellStopCasting()
					ccrCast("Ice Block")
					return
			else
				if ccrPlayerHasBuff("Ice Block") and ccrPlayerHealth() >= 20
					then
					CancelUnitBuff("player", "Ice Block")
					return
				end
			end
		
			-- Interrupt
		
			if ccrSpellCanAttack("Counterspell")
				and ccrTargetIsCastingOrChanneling()
				and ccrTargetIsInteruptable()
				and ccrTargetHasLeftOnCast(1)
					then
					ccrCastAttack("Counterspell")
					return
			end	
		
			--Thok Stopcasting
			
			if ccrTargetName("Thok the Bloodthirsty")
				and ccrTargetIsCastingSpell("Deafening Screech")
				then
				SpellStopCasting()
				return
			end
					
			-- Mirror Image
			
			if SpellIsReady("Mirror Image") and ccrTargetIsBoss()
				and not ccrPlayerIsCastingSpell("Evocation")
				then
				ccrCast("Mirror Image")
				return
			end
			
			-- Icy Veins
			
			if SpellIsReady("Icy Veins") and ccrPlayerHasBuff("Alter Time") and ccrTargetIsBoss()
				then
					ccrCast("Icy Veins")
				return
			end

			-- Alter Time
			
			if ccrPlayerHasBuff("Fingers of Frost") and ccrPlayerHasBuffStacks("Fingers of Frost", 2) and ccrPlayerHasBuff("Brain Freeze") and ccrPlayerHasBuff("Invoker's Energy") and SpellIsReady("Alter Time")	and ccrTargetIsBoss()
			or ccrPlayerHasBuff("Fingers of Frost") and ccrPlayerHasBuffStacks("Fingers of Frost", 2) and ccrPlayerHasBuffRemaining("Fingers of Frost", 4) and ccrPlayerHasBuff("Invoker's Energy") and SpellIsReady("Alter Time")	and ccrTargetIsBoss()
				then
					ccrCast("Alter Time")
				return
			end
			
		
			-- AOE
			if (ccrTargetCount(7) >= 3 and SpellIsReady("Inferno Blast"))
					then
					ccrCastAttack("Inferno Blast")
					return
			else
				if SpellIsReady("Cone of Cold") and ccR_HostilesNearPlayer(10) >= 3 and ccrPlayerIsFacingTarget()
							then
							ccrCastAttack("Cone of Cold")
							return
			else
					if ccR_HostilesNearPlayer(10) > 6
						then
						ccrCast("Arcane Explosion")
						return
			else
						if ccR_Mage_CheckForMissingBomb()
							then
								ccR_Mage_ApplyMissingBomb() 
							return
						end
					end
				end
			end									



			-- If moving
		if ccrPlayerIsFacingTarget() then	
			if ccrPlayerIsMoving() then
				if SpellIsReady("Ice Floes")
					then
					ccrCastAttack("Ice Floes")
					return
				else
					if SpellIsReady("Scorch")
						then
						ccrCastAttack("Scorch")
						return
					end
				end
			end
		end	
			
			--If not in raid
			
			if PlayerIsSOLO() then
				if not ccrPlayerHasBuff("Ice Barrier") and not ccrTargetName("Raider's Training Dummy")
					then
					ccrCastAttack("Ice Barrier")
					return
				end
				if  ccR_HostilesNearPlayer(10) > 1 and SpellIsReady("Frost Nova")
					then
					ccrCastAttack("Frost Nova")
					return
				else
					if SpellIsReady("Cone of Cold") and  ccR_HostilesNearPlayer(10) > 1 and ccrPlayerIsFacingTarget()
						then
						ccrCastAttack("Cone of Cold")
						return
					end
				end
			end
			
			
		if ccrPlayerIsFacingTarget() then
			-- Rotation
			if SpellIsReady("Frozen Orb") and ccrTargetCount(5) >= 3
				then
					ccrCast("Frozen Orb")
					return
			else
				if not ccrTargetName() ~= "Sha of Pride" and SpellIsReady("Frozen Orb") and ccrTargetIsBoss()
					then
					ccrCast("Frozen Orb")
					return
				else
					if SpellIsReady("Freeze") and not ccrTargetIsBoss()
						then
							ccrCastAttack("Freeze")
							if SpellIsTargeting() == 1 then CastAtLocation(GetAveragePositionOfObjects(tblPGetNearbyEnemies)) end
						return
					else
						if not (ccrTargetHasMyDebuff("Living Bomb") or ccrTargetHasMyDebuff("Nether Tempest") or ccrTargetHasMyDebuff("Frost Bomb"))
							and SpellIsReady("Mage Bomb")
							then
								ccrCastAttack("Mage Bomb")
							return
						else
							if ccrPlayerHasBuff("Brain Freeze") and onCD("Alter Time") or ccrPlayerHasBuff("Brain Freeze") and ccrPlayerHasBuffRemaining("Brain Freeze", 2)
								then
									ccrCastAttack("Frostfire Bolt")
								return
							else
								if ccrPlayerHasBuff("Brain Freeze") and not ccrTargetIsBoss()
									then
										ccrCastAttack("Frostfire Bolt")
									return
								else								
									if ccrPlayerHasBuff("Fingers of Frost") and onCD("Alter Time") or ccrPlayerHasBuff("Fingers of Frost") and ccrPlayerHasBuffRemaining("Fingers of Frost", 2)
										then
											ccrCastAttack("Ice Lance")
										return
									else
										if ccrPlayerHasBuff("Fingers of Frost") and not ccrTargetIsBoss()
											then
												ccrCastAttack("Ice Lance")
											return
										else
											if SpellIsReady("Frostbolt") and not  ccrPlayerHasBuff("Brain Freeze") and not ccrPlayerHasBuff("Fingers of Frost")
												then
													ccrCastAttack("Frostbolt")
												return
											end
										end	
									end	
								end	
							end	
						end
					end
				end
			end
		end	
	end	
end
